package com.googlecode.mgwt.examples.showcase.client.activities.animation;

import java.util.Date;

import com.google.gwt.user.client.ui.Widget;
import com.googlecode.mgwt.examples.showcase.client.AppController;
import com.googlecode.mgwt.examples.showcase.client.i18n.Labels;
import com.googlecode.mgwt.examples.showcase.client.model.DemoFloorEnum;
import com.googlecode.mgwt.examples.showcase.client.model.DemoProblemTypeEnum;
import com.googlecode.mgwt.examples.showcase.shared.ServiceCallDTO;
import com.googlecode.mgwt.ui.client.widget.FormListEntry;
import com.googlecode.mgwt.ui.client.widget.MListBox;
import com.googlecode.mgwt.ui.client.widget.MTextBox;
import com.googlecode.mgwt.ui.client.widget.ScrollPanel;
import com.googlecode.mgwt.ui.client.widget.WidgetList;

public class DemoServiceRequestViewImpl extends AbstractServiceRequestView {
	MListBox floorListBox    ;
	MListBox severityListBox ;
	MTextBox description;
	MTextBox reporter;
	MTextBox reporterContact;
	
	@Override
	protected void initModel() {
		floorListBox = new MListBox();       
		severityListBox = new MListBox();  
		description = new  MTextBox();   
		reporter = new  MTextBox();    
		reporterContact = new  MTextBox();
		
		for (DemoFloorEnum floor  : DemoFloorEnum.values()) {
			floorListBox.addItem(floor.getDisplayName());
		}
		for (DemoProblemTypeEnum problemType  : DemoProblemTypeEnum.values()) {
			severityListBox.addItem(problemType.getDisplayName());
		}
	}
	
	@Override
	public ServiceCallDTO getServiceCallDTO() {
		ServiceCallDTO dto = new ServiceCallDTO();
		dto.setFloorID(floorListBox.getSelectedIndex());
		dto.setTypeID(severityListBox.getSelectedIndex());
		dto.setDate(new Date());
		dto.setDescription(description.getText());
		dto.setReporter(reporter.getText());
		dto.setReporterContact(reporterContact.getText());
		return dto;
	}
	
	
	@Override
	public WidgetList getForm() {
		
		final WidgetList widgetList = new WidgetList(); 
		Labels labels = AppController.getClientFactory().getUserProfile().getCurrentUser().getLabels();
		widgetList.add(new FormListEntry(labels.floor(), floorListBox));
		widgetList.add(new FormListEntry(labels.severity(), severityListBox));
		widgetList.add(new FormListEntry(labels.description(), description));
		widgetList.add(new FormListEntry(labels.reporter(), reporter));
		widgetList.add(new FormListEntry(labels.reporterContact(), reporterContact));
		widgetList.setRound(true);
		return widgetList;
	}

}
